import * as XLSX from "xlsx";

export const defaultMockMenu = [
    {
        code: 'Banner',
        name: 'Banner管理',
    },
    {
        name: '商品管理',
        code: 'Product',
        children: [
            {
                name: '商品分类',
                code: 'ProductCategory',
            },
            {
                name: '商品列表',
                code: 'ProductList',
            },
        ]
    },
    {
        code: 'ProductOrder',
        name: '订单管理',
    },
    // {
    //     // 优惠券
    //     code: 'Coupon',
    //     name: '优惠券管理',
    // },
    {
        code: 'Member',
        name: '会员管理',
    },
    {
        name: '后台用户管理',
        code: 'user-management',
        children: [
            {
                name: '角色管理',
                code: 'role',
            },
            {
                name: '用户管理',
                code: 'user',
            }
        ]
    },
]

export function getStatus(item) {
    return '已完成'
    if (item.order_status === 0) {
        if (item.status === 1) {
            return '待支付'
        } else if (item.status === 2) {
            return '待发货'
        } else if (item.status === 3) {
            if (item.order_type == 1) {
                return '配送中'
            } else if (item.order_type == 0){
                return '待自提'
            }
        } else if (item.status === 4) {
            return '待收货'
        } else if (item.status === 5) {
            return '交易成功'
        }
    } else if (item.order_status === 1) {
        return '退款审核中'
    } else if (item.order_status === 2) {
        return '退款成功'
    } else if (item.order_status === 3) {
        return '退款失败'
    }
}

export const exportToExcel = (name,data = [], source = []) => {
    console.log(data)
    if (!name) {
        name = '导出文件'
    }
    if (!data) return
    // 创建一个工作簿
    const workbook = XLSX.utils.book_new();

    // 创建一个工作表
    const worksheet = XLSX.utils.aoa_to_sheet([
        ...data
    ]);

    // 将工作表添加到工作簿
    XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

    let startRow = 1;
    let endRow = 1;
    if (!worksheet['!merges']) {
        worksheet['!merges'] = [];
    }
    for (let i = 0; i < source.length; i++) {
        const order = source[i]
        endRow = startRow + order['orderGoodsDetails'].length - 1
        // 合并订单号和创建时间单元格
        worksheet['!merges'].push({
            s: { r: startRow, c: 0 },
            e: { r: endRow, c: 0 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 1 },
            e: { r: endRow, c: 1 }
        });

        worksheet['!merges'].push({
            s: { r: startRow, c: 8 },
            e: { r: endRow, c: 8 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 9 },
            e: { r: endRow, c: 9 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 10 },
            e: { r: endRow, c: 10 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 11 },
            e: { r: endRow, c: 11 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 12 },
            e: { r: endRow, c: 12 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 13 },
            e: { r: endRow, c: 13 }
        });

        worksheet['!merges'].push({
            s: { r: startRow, c: 16 },
            e: { r: endRow, c: 16 }
        });
        worksheet['!merges'].push({
            s: { r: startRow, c: 17 },
            e: { r: endRow, c: 17 }
        });
        startRow = endRow + 1; // 更新下一组订单的开始行
    }
    // 生成Excel文件
    XLSX.writeFile(workbook, name + '.xlsx');
};